package com.panfeng.xcloud.boss.provider.member.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.panfeng.xcloud.boss.provider.member.dto.request.GetFamilyTreeInfoListPageReqDTO;
import com.panfeng.xcloud.boss.provider.member.dto.request.GetFamilyTreeInfoReqDTO;
import com.panfeng.xcloud.boss.provider.member.dto.request.QueryUserInviterPageReqDTO;
import com.panfeng.xcloud.boss.provider.member.dto.response.GetFamilyTreeInfoListRespDTO;
import com.panfeng.xcloud.boss.provider.member.dto.response.GetFamilyTreeInfoRespDTO;
import com.panfeng.xcloud.boss.provider.member.dto.response.QueryUserInviterPageRespDTO;
import com.panfeng.xcloud.boss.provider.member.service.IUserInviterService;
import com.panfeng.xcloud.boss.provider.member.web.vo.request.GetFamilyTreeInfoListPageReqVO;
import com.panfeng.xcloud.boss.provider.member.web.vo.request.GetFamilyTreeInfoReqVO;
import com.panfeng.xcloud.boss.provider.member.web.vo.request.QueryUserInviterPageReqVO;
import com.panfeng.xcloud.boss.provider.member.web.vo.response.GetFamilyTreeInfoListRespVO;
import com.panfeng.xcloud.boss.provider.member.web.vo.response.GetFamilyTreeInfoRespVO;
import com.panfeng.xcloud.boss.provider.member.web.vo.response.QueryUserInviterPageRespVO;
import com.panfeng.xcloud.common.core.page.PageResponse;
import com.panfeng.xcloud.common.core.utils.ConvertUtils;
import com.panfeng.xcloud.common.core.web.vo.PageResponseVO;
import com.panfeng.xcloud.common.core.web.vo.ResponseVO;
import com.panfeng.xcloud.common.security.annotation.MethodValidate;
import com.panfeng.xcloud.common.security.annotation.NotNeedAccess;
import com.panfeng.xcloud.common.security.web.support.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 我的社区模块
 *
 * @author xiaobo
 * @version 1.0
 * @since 2019-08-08
 */
@RestController
@RequestMapping("user/inviter")
@Api(tags = {"我的社区模块"})
@Slf4j
public class UserInviterController extends BaseController {

    @Autowired
    private IUserInviterService iUserInviterService;

    /**
     * 查询我的社区列表
     *
     * @param getFamilyTreeInfoListPageReqVO
     * @param bindingResult
     * @return
     */
    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/getFamilyTreeInfoList")
    @ApiOperation(value = "查询我的社区列表(肖博)", httpMethod = "POST")
    public ResponseVO<List<GetFamilyTreeInfoListRespVO>> getFamilyTreeInfoList(@Validated @RequestBody GetFamilyTreeInfoListPageReqVO getFamilyTreeInfoListPageReqVO, BindingResult bindingResult) {
        log.info(">>>> 当前getFamilyTreeInfoList请求参数：{} <<<", (null != getFamilyTreeInfoListPageReqVO ? JSONObject.toJSONString(getFamilyTreeInfoListPageReqVO) : ""));
        GetFamilyTreeInfoListPageReqDTO getFamilyTreeInfoListPageReqDTO = ConvertUtils.convert(getFamilyTreeInfoListPageReqVO, GetFamilyTreeInfoListPageReqDTO.class);
        List<GetFamilyTreeInfoListRespDTO> pageDTO = iUserInviterService.getFamilyTreeInfoList(getFamilyTreeInfoListPageReqDTO);
        List<GetFamilyTreeInfoListRespVO> pageVO = ConvertUtils.convert(pageDTO, GetFamilyTreeInfoListRespVO.class);
        log.info(">>>> 当前getFamilyTreeInfoList响应报文：{} <<<", (null != pageVO ? JSONObject.toJSONString(pageVO) : ""));
        return ResponseVO.with(pageVO);
    }

    /**
     * 查询我的社区基本信息
     *
     * @param getFamilyTreeInfoReqVO
     * @param bindingResult
     * @return
     */
    @MethodValidate
    @NotNeedAccess
    @PostMapping(value = "/getFamilyTreeInfo", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询我的社区基本信息(肖博)", httpMethod = "POST", notes = "查询我的社区基本信息(肖博)")
    public ResponseVO<GetFamilyTreeInfoRespVO> getFamilyTreeInfo(@RequestBody @Valid GetFamilyTreeInfoReqVO getFamilyTreeInfoReqVO, BindingResult bindingResult) {
        logger.info(">>>> 当前getFamilyTreeInfo请求参数：{} <<<", (null != getFamilyTreeInfoReqVO ? JSONObject.toJSONString(getFamilyTreeInfoReqVO) : ""));
        GetFamilyTreeInfoReqDTO getFamilyTreeInfoReqDTO = ConvertUtils.convert(getFamilyTreeInfoReqVO, GetFamilyTreeInfoReqDTO.class);
        GetFamilyTreeInfoRespDTO getFamilyTreeInfoRespDTO = iUserInviterService.getFamilyTreeInfo(getFamilyTreeInfoReqDTO);
        GetFamilyTreeInfoRespVO getFamilyTreeInfoRespVO = ConvertUtils.convert(getFamilyTreeInfoRespDTO, GetFamilyTreeInfoRespVO.class);
        logger.info(">>>> 当前getFamilyTreeInfo响应内容：{} <<<", (null != getFamilyTreeInfoRespVO ? JSONObject.toJSONString(getFamilyTreeInfoRespVO) : ""));
        return ResponseVO.with(getFamilyTreeInfoRespVO);
    }

    /**
     * 查询直推人记录
     *
     * @param queryUserInviterPageReqVO
     * @param bindingResult
     * @return
     */
    @NotNeedAccess
    @MethodValidate
    @PostMapping(value = "/queryUserInviter", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询直推人记录(肖博)", httpMethod = "POST", notes = "查询直推人记录(肖博)")
    public ResponseVO<PageResponseVO<QueryUserInviterPageRespVO>> queryUserInviter(@RequestBody @Valid QueryUserInviterPageReqVO queryUserInviterPageReqVO, BindingResult bindingResult) {
        logger.info(">>>> 当前queryUserInviter请求参数：{} <<<", (null != queryUserInviterPageReqVO ? JSONObject.toJSONString(queryUserInviterPageReqVO) : ""));
        QueryUserInviterPageReqDTO queryUserInviterPageReqDTO = ConvertUtils.convert(queryUserInviterPageReqVO, QueryUserInviterPageReqDTO.class);
        PageResponse<QueryUserInviterPageRespDTO> pageDTO = iUserInviterService.queryUserInviter(queryUserInviterPageReqDTO);
        PageResponseVO<QueryUserInviterPageRespVO> pageVO = ConvertUtils.convertPage(pageDTO, QueryUserInviterPageRespVO.class);
        logger.info(">>>> 当前queryUserInviter响应内容：{} <<<", (null != pageVO ? JSONObject.toJSONString(pageVO) : ""));
        return ResponseVO.with(pageVO);
    }

}
